package com.deliveryservicesystem.service.impl;

import com.deliveryservicesystem.model.Product;
import com.deliveryservicesystem.model.Supplier;
import com.deliveryservicesystem.service.Report3;
import com.deliveryservicesystem.service.crud.impl.SupplierCrudServiceImpl;
import java.util.List;

/**
 * File Name: Report3Impl.java
 * Version:
 * Description:
 * Package: com.deliveryservicesystem.service.impl
 * Author: Lance
 * Date: Jul 29, 2012
 * Editor:
 */
public class Report3Impl implements Report3
{

    @Override
    public String getSupplierProducts(String supplierNo)
    {
        int productCount = 0;
        double productCost = 0;
        StringBuilder reportData = new StringBuilder();
        SupplierCrudServiceImpl crudService = new SupplierCrudServiceImpl();
        List<Supplier> suppliers = crudService.findEntities();

        for (Supplier supplier : suppliers)
        {
            if (supplier.getSupplierNo() == Integer.parseInt(supplierNo))
            {
                List<Product> products = supplier.getProductList();
                for (Product product : products)
                {
                    reportData.append(product.toString()).append("\n");
                    productCount++;
                    productCost += product.getProductPrice();
                }
            }
        }
        reportData.append("Report Summary\n====================\nTotal Cost: ").append(productCost).append("\nTotal Products:").append(productCount);
        return reportData.toString();
    }
}
